package com.chunyu.app.utils;

import java.util.Collection;
import java.util.Map;

public class NullUtils {

	/**
	 * 判断是否为NULL
	 * 
	 * @param obj
	 * @return
	 */
	public static final boolean isNull(Object obj) {
		if (null == obj) {
			return true;
		} else {
			return false;
		}
	}

	public static final boolean isNull(Long obj) {
		if (null == obj) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 判断是否为Not NULL
	 * 
	 * @param obj
	 * @return
	 */
	public static final boolean isNotNull(Object obj) {
		return !isNull(obj);
	}

	public static final boolean isEmpty(Object obj) {
		if (null == obj) {
			return true;
		} else if (obj instanceof String && "".equals(obj)) {
			return true;
		} else if ((obj instanceof Map<?, ?> && ((Map<?, ?>) obj).isEmpty())) {
			return true;
		} else if (obj instanceof Collection && ((Collection<?>) obj).isEmpty()) {
			return true;
		} else if (obj.getClass().isArray()) {
			return isEmptyArray(obj);
		} else if (obj.toString().trim().length() == 0) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isEmptyArray(Object array) {
		if (array instanceof Object[]) {
			return ((Object[]) array).length == 0;
		} else if (array instanceof boolean[]) {
			return ((boolean[]) array).length == 0;
		} else if (array instanceof byte[]) {
			return ((byte[]) array).length == 0;
		} else if (array instanceof char[]) {
			return ((char[]) array).length == 0;
		} else if (array instanceof double[]) {
			return ((double[]) array).length == 0;
		} else if (array instanceof float[]) {
			return ((float[]) array).length == 0;
		} else if (array instanceof int[]) {
			return ((int[]) array).length == 0;
		} else if (array instanceof long[]) {
			return ((long[]) array).length == 0;
		} else if (array instanceof short[]) {
			return ((short[]) array).length == 0;
		}
		return false;
	}

	public static final boolean isNotEmpty(Object obj) {
		return !isEmpty(obj);
	}

}
